package com.imooc.api;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

/**
 * @author 啊昌
 * @date 2025/9/20 16:52
 * ServiceLogAspect 统计impl 层的代理用时
 */
@Slf4j
@Aspect
@Component
public class ServiceLogAspect {
	@Around("execution(* com.imooc.service.impl..*.*(..))")
	public Object recordTimeLog(ProceedingJoinPoint joinPoint) throws Throwable {
		StopWatch stopWatch = new StopWatch();
		stopWatch.start();
		Object result = joinPoint.proceed(); //调用目标方法
		stopWatch.stop();
		log.info("[{}] 执行耗时: {} ms",
				joinPoint.getSignature().toShortString(),
				stopWatch.getTotalTimeMillis());
		return result;
	}
}
